#ifndef __dig_ENCODE_H_H_
#define __dig_ENCODE_H_H_

#include "stdint.h"

#ifdef __cplusplus
extern "C"
{
#endif

	typedef struct
	{
		uint8_t sample_time_cnt;
		uint8_t idle_time_cnt;

		int8_t in_flt;
		int8_t in_st;

		uint8_t bit_cnt;
		uint8_t bit_sv;
		uint8_t b_rx_ne;

		uint8_t snd_st;
		uint8_t rcv_st;

		uint8_t rcv_allow;
		uint8_t tx_allow;

		uint32_t rx_shift;
		uint32_t rx;
		uint32_t tx;

		void (*tx_out)(uint8_t st);
		uint8_t (*rx_in)(void);
		void (*io_dir)(uint8_t dir); 
	} dig_encode_type;

	void dig_encode_handle(dig_encode_type *obj);
	uint32_t dig_encode_read(dig_encode_type *obj);
	void dig_encode_write(dig_encode_type *obj, uint32_t dat);

	typedef struct
	{
		uint8_t act_time_cnt;
		uint8_t idle_time_cnt;

		int8_t in_st;

		uint8_t bit_cnt;
		uint8_t bit_sv; 

		uint8_t snd_st;
		uint8_t rcv_st;
		uint8_t rcv_err; 

		uint8_t b_rxne; 
		uint8_t b_txe;	

		uint32_t rx_shift;
		uint32_t rx;
		uint32_t tx;

		void (*tx_out)(uint8_t st);
		uint8_t (*rx_in)(void);
		void (*io_dir)(uint8_t dir); 
	} sig_encode_type;

	void sig_encode_handle(sig_encode_type *obj);			   
	uint32_t sig_encode_read(sig_encode_type *obj);			   
	void sig_encode_write(sig_encode_type *obj, uint32_t dat); 

#define SIM_UART_BUFF_LEN 8
	typedef struct
	{
		uint16_t tx;

		uint8_t over_load;

		uint8_t tx_next; 
		uint8_t tx_buff[SIM_UART_BUFF_LEN];

		void (*tx_out)(uint8_t st);
	} sim_uart_out_type;

	void sim_uart_bit_manage(sim_uart_out_type *obj);
	
	void sim_uart_send(sim_uart_out_type *obj, uint8_t dat);

#ifdef __cplusplus
}
#endif

#endif 
